home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.01 Jan 89 / Help / YourApp.Asm < prev    next >
Encoding:
Assembly Source File  |  1988-10-21  |  9.1 KB  |  387 lines  |  [TEXT/EDIT]

  1. ;What it does:
  2. ;Application Shell
  3.  
  4. ;Started: 
  5. ;Wed Oct 19, 1988 13:23:44
  6.  
  7. ;Finished:
  8. ;Fri Oct 21, 1988 12:06:02
  9.  
  10. ;By:
  11. ;John Holder
  12.  
  13.  
  14. Include     Traps.D            ; Use System and ToolBox traps
  15. Include     ToolEqu.D        ; Use ToolBox equates
  16. Include        SysEqu.D        ; Use System equates
  17. Include        FSEqu.D            ; Use File equates
  18.  
  19.  
  20. MACRO    SaveRegs    =
  21.     MOVEM.L        A0-A4/D0-D7,-(SP)
  22.     |
  23.  
  24. MACRO    RestoreRegs    =
  25.     MOVEM.L        (SP)+,A0-A4/D0-D7
  26.     |
  27.  
  28.  
  29.  
  30. XREF    DoHelp
  31.  
  32.  
  33. ; Offsets for Event Record:
  34. what         EQU    0    ; Event number
  35. message        EQU    2    ; Additional information
  36. when        EQU    6    ; Time event was posted 
  37. where        EQU    10    ; Mouse coordinates
  38. modify        EQU    14    ; State of keys and button
  39. wWindow        EQU    16    ; Find Window's Result
  40.  
  41. EventMask    EQU    $0000FFFF
  42.  
  43. ;menu equates
  44. AppleMenu    EQU    1    ;Apple Menu stuff
  45. AboutItem    EQU    1
  46. HelpItem    equ    2
  47.  
  48. FileMenu    EQU    2    ;File Menu stuff
  49. QuitItem    EQU    1
  50.  
  51. EditMenu    EQU    3    ;Edit Menu stuff
  52. UndoItem    EQU    1
  53. CutItem        EQU    3
  54. CopyItem    EQU    4
  55. PasteItem    EQU    5
  56. ClearItem    EQU    6
  57.  
  58.  
  59. true        equ    $0100
  60. false        equ    0
  61. Nil        equ    0
  62.  
  63. ;About Sample...  ALRT ID#
  64. InfoAlert    equ    130
  65.  
  66.  
  67. ;-----------------------------------------------------------------------------
  68. ;            <<<<< Initialize the managers >>>>>
  69. ;-----------------------------------------------------------------------------
  70.     PEA        -4(A5)            ; Quickdraw's global area
  71.     _InitGraf                ; Init Quickdraw
  72.     _InitFonts                ; Init Font Manager
  73.     MOVE.L        #$0000FFFF,D0        ; Flush all events
  74.     _FlushEvents    
  75.     _InitWindows                ; Init Window Manager
  76.     _InitMenus                
  77.     pea        Get_Outta_Here        ; Quit if bomb!
  78.     _InitDialogs                ; Init Dialog Manager
  79.     _TEInit                    ; Init Text Edit
  80.     _InitCursor                ; Turn on arrow cursor
  81.  
  82.     _MoreMasters
  83.     _MoreMasters
  84.  
  85.     bsr        SetUpMenus
  86.     bra        MainLoop
  87.  
  88.  
  89. ;-----------------------------------------------------------------------------
  90. ;            <<<<< In case of bomb >>>>>
  91. ;-----------------------------------------------------------------------------
  92. Get_Outta_Here
  93.  
  94.     MOVE.W        #Nil,-(SP)    ;unhilite all menus!
  95.     _HiliteMenu
  96.  
  97.     _ExitToShell
  98.  
  99.  
  100. ;-----------------------------------------------------------------------------
  101. ;            <<<<< Set up the menus >>>>>
  102. ;-----------------------------------------------------------------------------
  103. SetUpMenus
  104.     CLR.L        -(SP)
  105.     MOVE.W        #AppleMenu,-(SP)
  106.     _GetRMenu
  107.     MOVE.L        (SP)+,MenuOneHandle(A5)
  108.     
  109.     MOVE.L        MenuOneHandle(A5),-(SP)
  110.     CLR.W        -(SP)
  111.     _InsertMenu    
  112.  
  113.     MOVE.L        MenuOneHandle(A5),-(SP)
  114.     MOVE.L        #'DRVR',-(SP)
  115.     _AddResMenu        
  116.     CLR.L        -(SP)
  117.     MOVE.W        #FileMenu,-(SP)
  118.     _GetRMenu
  119.     MOVE.L        (SP),MenuTwoHandle(A5)    
  120.     CLR.W        -(SP)
  121.     _InsertMenu
  122.     CLR.L        -(SP)
  123.     MOVE.W        #EditMenu,-(SP)
  124.     _GetRMenu
  125.     MOVE.L        (SP),MenuThreeHandle(A5)    
  126.     CLR.W        -(SP)
  127.     _InsertMenu
  128.     _DrawMenuBar    
  129.     RTS
  130.  
  131. ;-----------------------------------------------------------------------------
  132. ;               <<<< Main Event Loop >>>>
  133. ;-----------------------------------------------------------------------------
  134. MainLoop
  135.     _SystemTask
  136.         CLR.W           -(SP)
  137.     MOVE         #EventMask,-(SP)    ; Allow 12 low events
  138.     PEA        eventRecord(A5)        ; Place to return results
  139.     _GetNextEvent                ; Look for an event
  140.     MOVE.W        (SP)+,D2    ;will be a 1 if application should respond
  141.     BEQ        MainLoop    ;(not sure about this one, maybe pass something to an accessory)
  142.  
  143.     move        eventRecord+what(A5),D0    ;respond
  144.     add        D0,D0
  145.     move        EventTable(D0),D0
  146.     jmp        EventTable(D0)    ;jump to appropriate routine
  147.  
  148. EventTable
  149.     dc        MainLoop-EventTable    ;null event
  150.     dc        MouseDown-EventTable      ;mouse down
  151.     dc        MainLoop-EventTable    ;mouse up
  152.     dc        KeyDown-EventTable    ;key down
  153.     dc        MainLoop-EventTable    ;key up
  154.     dc        KeyDown-EventTable    ;auto key
  155.     dc        MainLoop-EventTable      ;update event
  156.     dc        MainLoop-EventTable    ;disk event
  157.     dc        MainLoop-EventTable    ;activate event
  158.     dc        MainLoop-EventTable    ;abort
  159.     dc        MainLoop-EventTable    ;network event
  160.     dc        MainLoop-EventTable    ;I/O driver event
  161.  
  162.  
  163.  
  164. ;-----------------------------------------------------------------------------
  165. ;                <<<< Key Down Event >>>>
  166. ;-----------------------------------------------------------------------------
  167. KeyDown
  168.     clr.w        -(sp)
  169.     pea        eventRecord+Modify(A5)
  170.     move.l        #7,-(sp)
  171.     _BitTst
  172.     move.w        (sp)+,d1
  173.     bne        command_down
  174.     bra        MainLoop
  175.  
  176. command_down
  177.     clr.l        -(sp)
  178.     move.l        eventRecord+message(A5),D1
  179.     move.w        D1,-(sp)
  180.     _MenuKey
  181.     move.l        (sp)+,D4
  182.     cmp.l        #Nil,D4
  183.     beq        MainLoop    ;not menu choice!
  184.     bra        Menu_Key_Jump
  185.  
  186.  
  187.  
  188. ;-----------------------------------------------------------------------------
  189. ;            <<<< Handle Mouse Down Event >>>>
  190. ;-----------------------------------------------------------------------------
  191. MouseDown
  192.     CLR.W        -(SP)
  193.     MOVE.L        eventRecord+where(A5),-(SP)
  194.     PEA        TheWindow(A5)    ;returns the window ptr
  195.     _FindWindow
  196.     MOVE.W        (SP)+,D0    ;returns where the mouse was
  197.  
  198.     add        D0,D0
  199.     move        WindowTable(D0),D0
  200.     jmp        WindowTable(D0)        ;jump to appropriate routine
  201.  
  202. WindowTable
  203.     dc        MainLoop-WindowTable    ;In Desk
  204.     dc        InMenu-WindowTable        ;In Menu Bar
  205.     dc        SysWindow-WindowTable      ;In System Window
  206.     dc        MainLoop-WindowTable      ;in Content
  207.     dc        MainLoop-WindowTable      ;in drag
  208.     dc        MainLoop-WindowTable      ;in grow
  209.     dc        MainLoop-WindowTable      ;in go away
  210.  
  211.  
  212.  
  213. ;-----------------------------------------------------------------------------
  214. ;                 <<<< Click in Menu >>>>
  215. ;-----------------------------------------------------------------------------
  216. InMenu
  217.     CLR.L        -(SP)
  218.     MOVE.L        eventRecord+where(A5),-(SP)
  219.     _MenuSelect
  220.     MOVE.L        (SP)+,D4
  221.     CMP.L        #Nil,D4
  222.     BEQ        MainLoop    ;no item selected, go to main loop
  223.  
  224. Menu_Key_Jump    
  225.     MOVE.L        D4,D6        ;.W of D6 will now have the item #        
  226.     SWAP        D4        ;Put hi-word into low word of D4
  227.  
  228. WhichMenuWasIt
  229.     CMP.W        #AppleMenu,D4
  230.     BEQ        InAppleMenu    
  231.     CMP.W        #FileMenu,D4
  232.     BEQ        InFileMenu    
  233.     CMP.W        #EditMenu,D4
  234.     BEQ        InEditMenu    
  235.     BRA        MainLoop
  236.  
  237.  
  238. ;-----------------------------------------------------------------------------
  239. ;           <<<< Where all menu routines end their journey >>>>
  240. ;-----------------------------------------------------------------------------
  241. MenuDone
  242.     MOVE.W        #Nil,-(SP)    ;unhilite all menus!
  243.     _HiliteMenu
  244.     bra        MainLoop
  245.  
  246.  
  247.  
  248. ;-----------------------------------------------------------------------------
  249. ;                 <<<< In Apple Menu >>>>
  250. ;-----------------------------------------------------------------------------
  251. InAppleMenu    
  252.     CMP.W        #AboutItem,D6
  253.     BEQ        DoAbout
  254.     cmp        #HelpItem,D6
  255.     beq        DoTheHelp
  256.     Bra        DoDeskAcc
  257.     BRA        MainLoop
  258.  
  259.  
  260. ;-----------------------------------------------------------------------------
  261. ;                 <<<< Do About... >>>>
  262. ;-----------------------------------------------------------------------------
  263. DoAbout
  264.     bsr        SaveResFileandPort
  265.     move        thisresfile(A5),-(sp)
  266.     _UseResFile
  267.     CLR.W        -(SP)
  268.     MOVE.W        #InfoAlert,-(SP)
  269.     CLR.L        -(SP)
  270.     _Alert
  271.     MOVE.W        (SP)+,D0
  272.     bsr        RestoreResFileandPort
  273.     BRA        MenuDone
  274.  
  275.  
  276.  
  277. ;-----------------------------------------------------------------------------
  278. ;                 <<<< Do Help... >>>>
  279. ;-----------------------------------------------------------------------------
  280. DoTheHelp
  281.     bsr        DoHelp
  282.     bra        MenuDone
  283.  
  284.  
  285.  
  286. ;-----------------------------------------------------------------------------
  287. ;            <<<< Do a Desk Accessory >>>>
  288. ;-----------------------------------------------------------------------------
  289. DoDeskAcc
  290.     bsr        saveresfileandport
  291.  
  292.     MOVE.L        MenuOneHandle(A5),-(SP)
  293.     MOVE.W        D6,-(SP)
  294.     PEA        AccName(A5)
  295.     _GetItem
  296.  
  297.     CLR.W        -(SP)
  298.     PEA        AccName(A5)
  299.     _OpenDeskAcc
  300.     MOVE.W        (SP)+,D7
  301.  
  302.     bsr        restoreresfileandport
  303.     BRA        MenuDone
  304.  
  305.  
  306.  
  307. ;-----------------------------------------------------------------------------
  308. ;                 <<<< In File Menu >>>>
  309. ;-----------------------------------------------------------------------------
  310. InFileMenu
  311.     CMP.W        #QuitItem,D6
  312.     BEQ        Get_Outta_Here
  313.     BRA        MainLoop
  314.  
  315.  
  316.  
  317. ;-----------------------------------------------------------------------------
  318. ;                     <<<< Click in edit menu >>>>
  319. ;-----------------------------------------------------------------------------
  320. InEditMenu
  321.     sub.w        #1,D6        ;subtract 1 to correspond to below info
  322.     CLR.W        -(SP)
  323.     MOVE.W        D6,-(SP)    ;Undo=0,cut=2,copy=3,etc...
  324.     _SysEdit
  325.     MOVE.W        (SP)+,D0
  326.     BRA        MenuDone
  327.  
  328.  
  329.  
  330. ;-----------------------------------------------------------------------------
  331. ;                     <<<< Click in System Window >>>>
  332. ;-----------------------------------------------------------------------------
  333. SysWindow
  334.     bsr        saveresfileandport
  335.     PEA        eventRecord(A5)
  336.     MOVE.L        TheWindow(A5),-(SP)
  337.     _SystemClick
  338.     bsr        restoreresfileandport
  339.     BRA        MainLoop
  340.  
  341.  
  342.  
  343. ;-----------------------------------------------------------------------------
  344. ;-----------------------------------------------------------------------------
  345. ;                <<<< MISC. ROUTINES >>>>
  346. ;-----------------------------------------------------------------------------
  347. ;-----------------------------------------------------------------------------
  348.  
  349.  
  350. ;-----------------------------------------------------------------------------
  351. ;            <<<< save & restore current port & res file >>>>
  352. ;-----------------------------------------------------------------------------
  353. SaveResFileandPort
  354.     clr        -(sp)
  355.     _CurResFile
  356.     move        (sp)+,AResFile(A5)
  357.     pea        TheCurPort(A5)
  358.     _GetPort
  359.     rts
  360.  
  361. RestoreResFileandPort
  362.     move        AResFile(A5),-(sp)
  363.     _UseResFile
  364.     move.l        TheCurPort(A5),-(SP)
  365.     _SetPort
  366.     rts
  367.  
  368.  
  369. ;-----------------------------------------------------------------------------
  370. ;                  <<<<< Globals >>>>>
  371. ;-----------------------------------------------------------------------------
  372.  
  373. TheWindow    ds.l    1
  374. TheCurPort    ds.l    1
  375. AResFile    ds    1
  376. thisresfile    ds    1
  377.  
  378. MenuOneHandle    DS.L    1
  379. MenuTwoHandle    DS.L    1
  380. MenuThreeHandle    DS.L    1
  381.  
  382. eventRecord    DS.B     20    ; Event Record
  383.  
  384. AccName        DS.B    32    ; Desk Acc. Name
  385.  
  386.     END
  387.